# -*- encoding:utf-8 -*-
"""
@作者：ven
@文件名：mysqlUtil.py
@时间：2021-11-22  14:32
@文档说明:
# 需要下载mysql-connector，mysql-connector是MySQL官方提供的驱动器
# 下载命令：pip install mysql-connector
"""
import json
import traceback

import time

import pymysql
from config.config import MYSQL_DB
from utils.loguruUtil import log

#
# class MysqlConnectDatabase:
#     # 连接数据库
#     def __init__(self, charset='utf8'):
#         self.__host = MYSQL_DB['host']
#         self.__port = MYSQL_DB['port']  # mysql端口
#         self.__username = MYSQL_DB['user']  # mysql远程连接用户名
#         self.__password = MYSQL_DB['password']  # mysql远程连接密码
#         self.__db = MYSQL_DB['db']  # mysql使用的数据库名
#         self.__charset = charset  # mysql使用的字符编码,默认为utf8
#         try:
#             self.__connect_database = pymysql.connect(host=self.__host,
#                                                       port=self.__port,
#                                                       user=self.__username,
#                                                       password=self.__password,
#                                                       database=self.__db,
#                                                       charset=self.__charset)
#         except:
#             log.error(traceback.format_exc())
#             print('连接失败')
#         else:
#             self.cur = self.__connect_database.cursor()
#
#     # 操作数据库（增删改查等）
#
#     def query(self,sql):
#         try:
#
#             self.cur.execute(sql)
#             result = self.cur.fetchall()  # 数据库查询返回结果
#             self.cur.close()
#         except Exception as e:
#             log.info(f'查询结果为空:{e.args}')
#         else:
#             return result
#
#
#     def update(self, sql):
#         try:
#             self.cur.execute(sql)
#             self.__connect_database.commit()  # 增删改
#             result1 = self.cur.fetchall()
#             self.cur.close()
#
#         except Exception as e:
#             print('失败', e)
#             self.__connect_database.rollback()
#         else:
#             return result1
#
#
#     # 断开数据库连接
#     # def __del__(self):
#     #     # 这是对象销毁前执行的方法
#     #     self.__connect_database.close()
#
#
# conn = MysqlConnectDatabase()


